local skel = fk.CreateSkill {
  name = "lb__lihuan_active",
}

Fk:loadTranslationTable {
  ["lb__lihuan_active"] = "离焕",
  [":lb__lihuan_active"] = "<font color=#CC3131><b>生命纵如微尘</b></font>",
}

skel:addEffect("active", {
  mute = true,
  prompt = "#lb__lihuan",
  can_use = function(self, player)
    return player:usedSkillTimes("lb__lihuan") < 2 and
        table.find(player:getCardIds("h"), function(id)
          return Fk:getCardById(id):getMark("lb__lihuan-inhand") == 0
        end)
  end,
  min_card_num = 1,
  target_filter = Util.FalseFunc,
  card_filter = function(self, player, to_select, selected)
    return Fk:getCardById(to_select):getMark("lb__lihuan-inhand") == 0 and
    table.contains(player:getCardIds("h"), to_select)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    player:addSkillUseHistory("lb__lihuan")
    room:notifySkillInvoked(player, "lb__lihuan", "drawcard")
    player:broadcastSkillInvoke("lb__lihuan")
    local card_names = {}
    player:showCards(effect.cards)
    for _, id in ipairs(effect.cards) do
      local card = Fk:getCardById(id)
      if table.contains(Fk:getAllCardNames("bt"), card.name) and #card:getDefaultTarget(player) > 0 then
        table.insertIfNeed(card_names, card.name)
      end
    end
    card_names = player:getViewAsCardNames("lb__lihuan", card_names)
    if #card_names > 0 then
      room:askToUseVirtualCard(player, {
        name = card_names,
        skill_name = skel.name,
        cancelable = false,
      })
      local cards = table.filter(effect.cards, function(id)
        return (room:getCardArea(id) == Card.PlayerHand) and (room:getCardOwner(id) == player)
      end)
      if #cards > 0 then
        room:recastCard(cards, player, "lb__lihuan")
      end
    else
      room:askToUseVirtualCard(player, {
        name = "fire_attack",
        skill_name = "lb__lihuan_use",
      })
    end
  end,
})

return skel
